<template>
  <div id="test">
    <p>action</p>
    <el-button class="btn1" @click="getFid">获取一级分类</el-button>
    <el-button type="danger" @click="getSid">获取二级分类</el-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      fid: ''
    }
  },
  methods: {
    // 点击发请求，获取一级分类
    getFid() {
      // this.$store.dispatch('getFid')
      this.$http('http://www.ujiuye.tech:3000/api/category/first')
        .then(res => {
          this.$store.commit('setFid', res.data.result.data[0].first_id);
        })
    },
    getSid() {
      // this.$store.dispatch('getSid')
      // this.$http('/category/second?first_id=dfdf')
      this.$http('http://www.ujiuye.tech:3000/api/category/second',{params: {id: this.$store.state.first_id}})
        .then(res => {
          let sid = res.data.result.data[0].second_id;
          this.$store.commit('setSid', sid)
        })
    }
  }
}
</script>
<style lang="">
  #test .btn1 {
    font-size: 100px;
  }
</style>